﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model;
using Model.EntityModel;
using Person = Model.EntityModel.Person;

namespace Project
{
    /// <summary>
    /// Interaction logic for PrintDeclaration.xaml
    /// </summary>
    public partial class PrintDeclaration : UserControl
    {
         private long ComplaintId;
        private List<ShowableQuestion> DeclarationQuestions;
        private Declaration declaration;

        public PrintDeclaration(long complaintId, List<ShowableQuestion> declarationQuestions)
        {
            ComplaintId = complaintId;
            DeclarationQuestions = declarationQuestions;
            InitializeComponent();
            listBoxQuestions.DataContext = DeclarationQuestions;
            declaration =
                DeclarationDataAccess.GetDeclarationsById(declarationQuestions.FirstOrDefault().DeclarationId);
            lblCurrentTime.Content = declaration.RegistrationDate.ToShortTimeString();
            lblTodayDate.Content = declaration.RegistrationDate.ToShortDateString();
            lblRegistrationDate.Content = lblTodayDate.Content;
            lblCaseNumber.Content = declaration.ComplaintId;
            lblCaseNum.Content = lblCaseNumber.Content;
            var Aggressor = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Agresor", ComplaintId).Person;
            lblAggressor.Content = Aggressor.Name + " " + Aggressor.PaternalName + " " + Aggressor.MaternalName;
            SetPersonalInfoContext(DeclarationDataAccess.GetDeclarationsById(DeclarationQuestions.FirstOrDefault().DeclarationId).Actor.Person);
            PersonInfo.Header = "Datos Personales de "+
                DeclarationDataAccess.GetDeclarationsById(declarationQuestions.FirstOrDefault().DeclarationId).Actor.
                    Type;
            var employees = ComplaintDataAccess.GetAllEmployeeOfComplaintFromComp(ComplaintId);
            foreach (var employeeOfComplaint in employees)
            {
                if (employeeOfComplaint.Responsability == "Asignada")
                    lblAsigned.Content = employeeOfComplaint.Employee.Name + " " +
                                             employeeOfComplaint.Employee.PaternalName + " " +
                                             employeeOfComplaint.Employee.MaternalName;
            }
        }

        public void SetPersonalInfoContext(Person person)
        {
            if (person != null)
            {
                tbActorName.Content = person.Name;
                tbActorLastName.Content = person.PaternalName;
                tbActorMiddleName.Content = person.MaternalName;
                tbActorCI.Content = person.CiPassport == 0 ? "" : person.CiPassport.ToString();
                tbActorAddress.Content = person.Address;
                tbActorPhone.Content = person.Phone;
                tbActorZone.Content = person.Zone;
                tbActorWorkPlace.Content = person.WorkPlace;
                cboxActorCountry.Content = person.Nationality;
                cbActorCivilStatus.Content = person.CivilStatus;
            }
        }
    }
}
